package com.gaozhaoyang.dao;

import com.gaozhaoyang.entity.User;
import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;

/*
* 对user表进行增删改查
* */
public class UserDao {
    ComboPooledDataSource dataSource = new ComboPooledDataSource();
    QueryRunner qr= new QueryRunner(dataSource);

    public User findUserByUserNameAndPassword(String username, String password){
        String sql = "select * from user where username = ? and password = ?";
        try {
            return  qr.query(sql,new BeanHandler<User>(User.class),username,password);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }
}
